package com.ruoyi.web.controller.hr.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hr.domain.Value;
import com.ruoyi.hr.service.IValueService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * hr表相关操作Controller
 * 
 * @author lyh
 * @date 2020-11-18
 */
@Controller
@RequestMapping("/hr/value")
public class ValueController extends BaseController
{
    private String prefix = "hr/value";

    @Autowired
    private IValueService valueService;

    @RequiresPermissions("hr:value:view")
    @GetMapping()
    public String value()
    {
        return prefix + "/value";
    }

    /**
     * 查询hr表相关操作列表
     */
    @RequiresPermissions("hr:value:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Value value)
    {
        startPage();
        List<Value> list = valueService.selectValueList(value);
        return getDataTable(list);
    }

    /**
     * 导出hr表相关操作列表
     */
    @RequiresPermissions("hr:value:export")
    @Log(title = "hr表相关操作", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Value value)
    {
        List<Value> list = valueService.selectValueList(value);
        ExcelUtil<Value> util = new ExcelUtil<Value>(Value.class);
        return util.exportExcel(list, "value");
    }

    /**
     * 新增hr表相关操作
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存hr表相关操作
     */
    @RequiresPermissions("hr:value:add")
    @Log(title = "hr表相关操作", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Value value)
    {
        return toAjax(valueService.insertValue(value));
    }

    /**
     * 修改hr表相关操作
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Value value = valueService.selectValueById(id);
        mmap.put("value", value);
        return prefix + "/edit";
    }

    /**
     * 修改保存hr表相关操作
     */
    @RequiresPermissions("hr:value:edit")
    @Log(title = "hr表相关操作", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Value value)
    {
        return toAjax(valueService.updateValue(value));
    }

    /**
     * 删除hr表相关操作
     */
    @RequiresPermissions("hr:value:remove")
    @Log(title = "hr表相关操作", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(valueService.deleteValueByIds(ids));
    }
}
